package com.xbxkj.controller.controller;


import com.xbxkj.controller.util.AddressUtils;
import com.xbxkj.controller.util.IpUtils;
import com.xbxkj.controller.util.domain.Server;
import com.xbxkj.fegin.cilent.EvaluateFegin;
import com.xbxkj.util.Respons.ResponseUtil;
import com.xbxkj.util.auth.AuthSign;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * <p>
 * 评价 前端控制器
 * </p>
 *
 * @author 张子艺
 * @since 2019-07-17
 */
@Controller
@RequestMapping("/api/evaluate")
public class EvaluateController {
    private     Logger logger = LoggerFactory.getLogger(EvaluateController.class);
    @Autowired
    EvaluateFegin evaluateFegin;


    @RequestMapping(value = "/list")
    @ResponseBody
    public Map findEvaluate(HttpServletRequest request) {
        Map map = new HashMap();
        try{
            map = evaluateFegin.list();
        }catch (Exception e){
            logger.error("查询失败，错误信息：",e.getMessage() );
        }

       String ip= IpUtils.getIpAddr(request);
        logger.info("当前IP:{},地址为：{}", ip, AddressUtils.getRealAddressByIP(ip));
        return  map ;
    }


    /**
     * 获取服务器状态
     * @return
     */
    @RequestMapping(value = "/server")
    @ResponseBody
    public Map server( )  {
        Server server = new Server();
        try {
            server.copyTo();
        } catch (Exception e) {
            logger.error("获取服务器状态失败，错误信息：",e.getMessage() );;
        }
        return ResponseUtil.getSuccessMap(server);
    }

}
